package countBeautifulPairs;

public class Solution {
    public int countBeautifulPairs(int[] nums) {
        int count = 0;
        for (int i = 0; i < nums.length-1; i++) {
            for (int j = i+1; j < nums.length; j++) {
                if(check(getFirst(nums[i]),getLast(nums[j]))){
                    count++;
                }
            }
        }
        return count;
    }
    private boolean check(int a,int b){
        int t = Math.min(a,b);
        for (int i = 2; i <= t ; i++) {
            if(a%i==0&&b%i==0){
                return false;
            }
        }
        return true;
    }
    private int getFirst(int n){
        return Integer.toString(n).charAt(0)-'0';
    }
    private int getLast(int n){
        String s = Integer.toString(n);
        return s.charAt(s.length()-1)-'0';
    }
}
